﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Text;
using System.Xml;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using EQT.Model;

namespace EQT.Dal
{
    public partial class DaEquipMaintainLog
    {
        /// <summary>
        /// 分页查询设备维修记录。
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="PageSize"></param>
        /// <param name="PageIndex"></param>
        /// <param name="TotalCount"></param>
        /// <returns></returns>
        public DataSet GetEquipMtRecords(string condition, int PageSize, int PageIndex, out int TotalCount)
        {

            string strGetEmploreeRecords = "select * from V_Equip_Mt ";

            if (!string.IsNullOrEmpty(condition))
            {
                strGetEmploreeRecords = strGetEmploreeRecords + condition;
            }

            try
            {
                return DaCommon.GetPaginationData(strGetEmploreeRecords, PageSize, PageIndex, " Equi_Mtn_ID desc", out TotalCount);

            }
            catch (DbException ex)
            {
                HandleDbException(ex);
            }
            TotalCount = 0;
            return new DataSet();
        }

        /// <summary>
        /// 按条件查询设备维修记录。
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public DataSet GetEquipMtRecords(string condition)
        {
            string strGetEmploreeRecords = "select * from V_Equip_Mt ";

            if (!string.IsNullOrEmpty(condition))
            {
                strGetEmploreeRecords = strGetEmploreeRecords + condition;
            }

            try
            {
                return db.ExecuteDataSet(CommandType.Text, strGetEmploreeRecords);
            }
            catch (DbException ex)
            {
                HandleDbException(ex);
            }
            return new DataSet();
        }

        public DataSet GetMtDetail(string Equi_Mtn_ID)
        {
            try
            {
                string strGetEmploreeRecords = "select * from V_Equip_Mt where Equi_Mtn_ID='" + Equi_Mtn_ID + "'";
                return db.ExecuteDataSet(CommandType.Text, strGetEmploreeRecords);
            }
            catch (DbException ex)
            {
                HandleDbException(ex);
            }
            return new DataSet();
        }

        public int CreateMtLog(MoEquipMaintainLog entity)
        {
            string SQL_INSERT="INSERT INTO Equip_Maintain_Log (Equip_ID ,Emp_ID ,Mtn_Date ,Mtn_Info ) VALUES "
			+"(@Equip_Id,@Emp_Id,@Mtn_Date,@Mtn_Info)";
            try
            {
                DbCommand dbCommand = db.GetSqlStringCommand(SQL_INSERT);

                //设置参数:Equip_Id	
                db.AddInParameter(dbCommand, "Equip_Id", DbType.AnsiString, entity.Equip_Id);
                //设置参数:Emp_Id	
                db.AddInParameter(dbCommand, "Emp_Id", DbType.AnsiString, entity.Emp_Id);
                //设置参数:Mtn_Date	
                db.AddInParameter(dbCommand, "Mtn_Date", DbType.DateTime, entity.Mtn_Date);
                //设置参数:Mtn_Info	
                db.AddInParameter(dbCommand, "Mtn_Info", DbType.String, entity.Mtn_Info);
			 
                return db.ExecuteNonQuery(dbCommand);
            }
            catch (DbException ex)
            {
                HandleDbException(ex, entity);
            }
            return 0;
        }
    }
}
